<template>
    <div class="template-list">
        <div class="template-item" v-for="item in props.list" :key="item.id">
            <div class="template-img" @click="item.url ? onPreview(item) : ''">
                <NuxtImg :alt="item.name" :title="item.name" class="cover-img" :src="item.file +
                    '?x-oss-process=image/resize,w_864/watermark,image_' +
                    toBase64(
                        'water/logo_white.png?x-oss-process=image/resize,P_30'
                    ) +
                    ',g_center,t_60/format,webp'
                    " loading="lazy" />
                <img class="preview" :src="`${_oss_}images/template/preview.png`" alt="北京华锐云空间" />
                <img class="free-icon" v-if="item.templatestype_code == 'courseware'"
                    :src="`${_oss_}images/free-icon.png`" />
            </div>

            <div class="template-info">
                <div class="template-top">
                    <div class="template-name" :title="item.name">
                        {{ item.name }}
                    </div>
                    <el-button class="btn-jump" type="primary" :disabled="!item.url"
                        @click.stop="item.url ? onMakeModel(item) : ''">
                        {{ item.is_buy == 1 ? "开始创作" : "免费制作" }}
                    </el-button>
                </div>

                <div class="template-footer">
                    <div class="icon-group">
                        <template v-if="item.templatestype_code == 'template'">
                            <div class="icon-item">
                                <img :src="`${_oss_}images/template/icon-area.svg`" />
                                {{ item.area }}m²
                            </div>
                        </template>
                        <div class="icon-item">
                            <img :src="`${_oss_}images/template/icon-eye.svg`" />
                            {{ item.page_view }}
                        </div>

                        <div class="sales-volume" v-if="IsNeedPay(item)">
                            已销售：{{ item.sales || 0 }}
                        </div>
                    </div>

                    <el-button :type="item.is_buy == 1 ? 'warning' : 'primary'" @click.stop="onBuyModel(item)"
                        onfocus="this.blur()" v-if="IsNeedPay(item)" :disabled="!item.url">
                        {{ item.is_buy == 1 ? "可升级" : "购买" }}
                    </el-button>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
import { onMakeModel, onPreview, IsNeedPay, onBuyModel } from ".";
const props = defineProps({
    list: {
        type: Array,
        default: () => [],
    },
    type: {
        type: [Number, String],
        default: 0,
    },
});
</script>
<style lang="scss" scoped>
.template-list {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;

    .template-item {
        position: relative;
        width: 288px;
        background-color: #fff;
        border-radius: 10px;
        overflow: hidden;
        margin-right: 16px;
        margin-bottom: 48px;
        transition: transform 0.5s;

        &:hover {
            transform: translateY(-10px);
            box-shadow: 0px 0px 20px 0px rgba(1, 23, 86, 0.5);
        }

        .free,
        .price {
            position: absolute;
            left: 0;
            top: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: 10px 0 10px 0;
            font-size: 14px;
            color: #fff;
        }

        .price {
            width: 90px;
            height: 26px;
            background: linear-gradient(-90deg, #ff3527, #ff8846);
        }

        .free {
            width: 46px;
            height: 26px;
            background: #999999;
        }

        &:nth-of-type(4n) {
            margin-right: 0;
        }

        .top {
            position: absolute;
            top: 11px;
            right: 16px;
            font-size: 14px;
            color: #fff;
            z-index: 9;
        }

        .template-img {
            position: relative;
            width: 100%;
            height: 156px;
            overflow: hidden;
            cursor: pointer;

            &:hover {
                .cover-img {
                    transform: scale(1.4);
                }

                .preview {
                    opacity: 1;
                }
            }

            .free-icon {
                position: absolute;
                top: 0;
                right: 0;
            }

            .cover-img {
                width: 100%;
                height: 100%;
                object-fit: cover;
                transition: all 0.4s linear;
            }

            .preview {
                opacity: 0;
                position: absolute;
                left: 0;
                top: 0;
                transition: all 0.4s linear;
            }
        }

        .template-info {
            padding: 16px 10px 10px;

            .template-top {
                display: flex;
                align-items: center;
                height: 30px;

                .template-name {
                    font-size: 18px;
                    width: 180px;
                    font-weight: 500;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }

                .el-button {
                    margin-top: 5px;
                    margin-left: auto;

                    &:first-of-type {
                        margin-top: 0px;
                    }

                    // &.btn-jump:hover {
                    //     color: #fff;
                    //     border-color: #5085fb;
                    //     background-color: #5085fb;
                    //     outline: none;
                    // }
                }
            }

            .el-button {
                padding: 0 !important;
                width: 80px;
                height: 30px;
            }
        }

        .template-title {
            font-size: 18px;
            color: #333;
        }

        .template-footer {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-top: 17px;
            height: 30px;

            .icon-group {
                width: 180px;
                display: flex;
                align-items: center;
                color: #999;
                font-size: 12px;

                .icon-item {
                    display: inline-flex;
                    align-items: center;
                    margin-right: 9px;

                    img {
                        width: 12px;
                        margin-right: 3px;
                    }
                }

                .sales-volume {
                    font-size: 12px;
                    color: #999;
                }
            }
        }

        .template-price {
            font-size: 14px;
            color: #666666;
            margin-right: auto;
        }
    }
}
</style>
